// Help
//
// 保佑没Bug
//
// Created by AS on 2019/4/10.
//
// Copyright © 2018 AS. All rights reserved.
//

#import "CModel.h"
#import "PhotosView.h"
@implementation CModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{@"Id": @"id"};
}

-(NSString *)createTime{
    
    NSDateFormatter *fmt = [[NSDateFormatter alloc]init];
    //    fmt.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *createDate = [fmt dateFromString:_createTime];
    NSDate *new = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDateComponents *cmps = [calendar components:unit fromDate:createDate toDate:new options:0];
    if([createDate isThisYear]){ //是否是今年
        if([createDate isYesterday]){ //是否是昨天
            fmt.dateFormat = @"昨天 HH:mm";
            return [fmt stringFromDate:createDate];
        }else if([createDate isToday]){ //是否是今天
            if(cmps.hour >= 1){
                return [NSString stringWithFormat:@"%d小时前",(int)cmps.hour];
            }else if(cmps.minute >= 1 && cmps.hour < 1){
                return [NSString stringWithFormat:@"%d分钟前",(int)cmps.minute];
            }else{
                return @"刚刚";
            }
        }else{
            fmt.dateFormat = @"MM-dd HH:mm";
            return [fmt stringFromDate:createDate];
        }
    }else{
        fmt.dateFormat = @"yyyy-MM-dd";
        return [fmt stringFromDate:createDate];
    }
}

-(void)setImgs:(NSString *)imgs{
    _imgs = imgs;
    _photos = [imgs componentsSeparatedByString:@","];
}
-(void)setGradeCode:(NSInteger)gradeCode{
    _gradeCode = gradeCode;
    switch (gradeCode) {
        case 1:
            _gradeName = @"普通用户";
            break;
        case 2:
            _gradeName = @"青铜用户";
            break;
        case 3:
            _gradeName = @"白银用户";
            break;
        case 4:
            _gradeName = @"黄金用户";
            break;
        case 5:
            _gradeName = @"铂金用户";
            break;
        case 6:
            _gradeName = @"钻石用户";
            break;
        case 7:
            _gradeName = @"皇冠用户";
            break;
        case 8:
            _gradeName = @"计划大神";
            break;
        default:
            _gradeName = @"";
            break;
    }
}

@end


@implementation CModelFrame


-(void)setModel:(CModel *)model{
    _model = model;
    
    CGFloat margin = 10;
    
    self.avatarF = CGRectMake(12, 12, 40, 40);
    
    self.typeF = CGRectMake(12, CGRectGetMaxY(self.avatarF) - 10, 40, 15);
    
    CGSize size = [model.nickName sizeWithFont:Font14];
    self.nameF = CGRectMake(CGRectGetMaxX(self.avatarF) + margin, 15, size.width, size.height);
    
    size = [model.gradeName sizeWithFont:Font12];
    self.levelF = CGRectMake(CGRectGetMaxX(self.avatarF) + margin, CGRectGetMaxY(self.nameF)+3, size.width, size.height);
    
    size = [model.content sizeWithFont:Font16 maxW:ScreenWidth - 24];
    self.contentF = CGRectMake(12, CGRectGetMaxY(self.typeF) + margin,ScreenWidth - 24, size.height);
    
    CGFloat orginalH = 0;
    if (model.photos.count) {
        CGFloat photoX = 12;
        CGFloat photoY = CGRectGetMaxY(self.contentF) + margin;
        CGSize photoSize = [PhotosView sizeWithCont:model.photos.count];
        self.photoViewF = (CGRect){{photoX,photoY},photoSize};
        orginalH = CGRectGetMaxY(self.photoViewF) + 15;
    }else{
        orginalH = CGRectGetMaxY(self.contentF) + 15;
    }
    
    self.timeIconF = CGRectMake(12, orginalH,15, 15);
    self.cellHeight = CGRectGetMaxY(self.timeIconF) + 15;
}




@end
